﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLayer;
using System.Windows.Forms;

public partial class Administrator_RoleEdit : System.Web.UI.Page
{
    string cmd;
    int Id;

    protected void Page_Load(object sender, EventArgs e)
    {
        cmd = Request.QueryString["cmd"];

        rbStatus.Enabled = true;
        btnNew.Enabled = false;
        btnUpdate.Enabled = true;
        Id = Convert.ToInt32(Request.QueryString["Id"]);

        if (!IsPostBack)
            FillData(Role.GetOne(Id));
    }

    private void FillData(Role role)
    {
        txtName.Text = role.Role_Name;
        txtUrl.Text = role.Role_Url;
        txtDetail.Value = role.Role_Detail;
        rbStatus.Items.FindByValue(role.Role_Status.ToString()).Selected = true;
    }

    protected void BbtnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("Role.aspx");
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Role role = new Role();
        role.Role_Name = txtName.Text;
        role.Role_Url = txtUrl.Text;
        role.Role_Detail = txtDetail.Value;
        role.Role_Status = 0;

        try
        {
            Role.Update(role);
            MessageBox.Show("Role đã được sửa thành công!");
            Response.Redirect("Role.aspx");
        }
        catch (Exception ex)
        {
            MessageBox.Show("Lỗi !!! Mời bạn thử lại!");
            throw ex;
        }
    }
}